// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   LangBtnsPanel.java

package com.boci.common.ui.control;

import com.boci.clientapp.main.ApplicationService;
import com.boci.clientapp.main.ClientAppLoader;
import com.boci.common.constant.ClientAppConst;
import com.boci.common.util.MessagesConfigurator;
import com.boci.common.util.PerformanceLogger;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;
import javax.swing.JButton;
import javax.swing.JPanel;

public class LangBtnsPanel extends JPanel
    implements ActionListener
{

    public LangBtnsPanel(Locale pLocale)
    {
        currentLocale = pLocale;
        initConfig();
        initGUI();
        setText(pLocale);
    }

    public Locale getCurrentLocale()
    {
        return currentLocale;
    }

    public void setText(Locale pLocale)
    {
        currentLocale = pLocale;
        if(pLocale.equals(ClientAppConst.ZH_CN))
        {
            btnSC.setVisible(false);
            btnTC.setVisible(true);
            btnEN.setVisible(true);
        } else
        if(pLocale.equals(ClientAppConst.ZH_HK))
        {
            btnSC.setVisible(true);
            btnTC.setVisible(false);
            btnEN.setVisible(true);
        } else
        if(pLocale.equals(ClientAppConst.EN_US))
        {
            btnSC.setVisible(true);
            btnTC.setVisible(true);
            btnEN.setVisible(false);
        }
    }

    private void initConfig()
    {
        MessagesConfigurator msgConf = ClientAppLoader.getMessagesConfigurator();
        strCN = msgConf.getUIMessages("COMMON.LANGUAGE", ClientAppConst.ZH_CN);
        strTW = msgConf.getUIMessages("COMMON.LANGUAGE", ClientAppConst.ZH_HK);
        strEN = msgConf.getUIMessages("COMMON.LANGUAGE", ClientAppConst.EN_US);
    }

    private void initGUI()
    {
        btnSC = new JButton();
        btnTC = new JButton();
        btnEN = new JButton();
        btnSC.setText(strCN);
        btnTC.setText(strTW);
        btnEN.setText(strEN);
        btnSC.setFont(new Font("MingLiU", 0, 12));
        btnTC.setFont(new Font("MingLiU", 0, 12));
        btnEN.setFont(new Font("Arial", 0, 11));
        btnSC.setMargin(new Insets(0, 0, 0, 0));
        btnTC.setMargin(new Insets(0, 0, 0, 0));
        btnEN.setMargin(new Insets(0, 0, 0, 0));
        btnSC.setPreferredSize(new Dimension(20, 20));
        btnTC.setPreferredSize(new Dimension(20, 20));
        btnEN.setPreferredSize(new Dimension(20, 20));
        btnSC.setActionCommand("SIMPLIFIED_CHINESE");
        btnTC.setActionCommand("TRADITIONAL_CHINESE");
        btnEN.setActionCommand("ENGLISH");
        btnSC.addActionListener(this);
        btnTC.addActionListener(this);
        btnEN.addActionListener(this);
        setPreferredSize(new Dimension(40, 22));
        setLayout(new FlowLayout(1, 0, 1));
        add(btnTC);
        add(btnSC);
        add(btnEN);
    }

    public void actionPerformed(ActionEvent e)
    {
        PerformanceLogger.startAppTimer();
        Locale newLocale = ClientAppConst.ZH_CN;
        if(e.getActionCommand().equals("SIMPLIFIED_CHINESE"))
        {
            setText(ClientAppConst.ZH_CN);
            newLocale = ClientAppConst.ZH_CN;
        } else
        if(e.getActionCommand().equals("TRADITIONAL_CHINESE"))
        {
            setText(ClientAppConst.ZH_HK);
            newLocale = ClientAppConst.ZH_HK;
        } else
        if(e.getActionCommand().equals("ENGLISH"))
        {
            setText(ClientAppConst.EN_US);
            newLocale = ClientAppConst.EN_US;
        }
        ApplicationService.getInstance().setText(newLocale);
        PerformanceLogger.stopAppTimer();
        PerformanceLogger.doLog("LANGUAGE.CHANGE");
    }

    private JButton btnSC;
    private JButton btnTC;
    private JButton btnEN;
    private String strCN;
    private String strTW;
    private String strEN;
    private Locale currentLocale;
    private static final String SIMPLIFIED_CHINESE = "SIMPLIFIED_CHINESE";
    private static final String TRADITIONAL_CHINESE = "TRADITIONAL_CHINESE";
    private static final String ENGLISH = "ENGLISH";
}
